package com.highcom.exception;

import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

//@Component
//@ControllerAdvice //设置当前类为异常处理类
public class ExceptionAdvice {

    //定义@ExceptionHandler，后面添加实际处理的异常类型

    @ExceptionHandler(NullPointerException.class)
    //@ExceptionHandler(BusinessException.class)
    @ResponseBody
    public String doNullPointerException(Exception ex){
        return "NullPointerException";
    }

    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody
    public String doArithmeticException(Exception ex){
        return "ArithmeticException";
    }
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public String doException(Exception ex){
        return "Exception";
    }
}
